<?php
/************************************************************************/
/* FrameWork  test preview                                              */
/* ==================================================================== */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
//carica la lingua se esiste
//$lang=lang();
//if (file_exists("applications/$appname/lang/$lang.inc"))
//    include "applications/$appname/lang/$lang.inc";
//else
//    include "applications/$appname/lang/it.inc";

//library auto load
$i=0;
$fd=opendir("libs/");
while (false !== ($nf= readdir($fd))){
    //if ($nf[0]!='.' && $nf[0]!='_'  )
    if( substr($nf,0,3)=="al_")
	$libs[$i++]=$nf;
}
closedir($fd);
if ($i>0){
    sort($libs);
    foreach($libs as $lib){
	if (is_dir("libs/$lib"))
	    include "libs/$lib/lib.inc";
	else
	    include "libs/$lib";
    }
}

?>

      <h3><?=_REGUSER;?></h3><hr />
      <?php $user=user_getuser();
	    $avatar=$_GET['avatar'];
	    if ($avatar!="")$user_avatar=$avatar;//autoreload dell'avatar
	if ($user=="" ){  //hai scelto la registrazione user ?>
        <?php if ($_GET['user_op']!="reguser"){
	//se ti devi registrare ?>
          <form name="reguser" action="reguser.php?op=reguser&user_op=reguser" method="post" enctype="multipart/form-data" onsubmit="if( document.reguser.password.value != document.reguser.password2.value ){alert('<?=_PASSWORD_NON_CORRETTA_REINSERIRE;?>');return false;} ">
	    <b><?=_USER;?></b><input name='user' type="test" value=""/><br />
	    <b><?=_PASSWORD;?> </b><input name='password' type="password" value=""/>
	    <b><?=_RETYPE_PASSWORD;?></b><input name='password2' type="password" value="" /><br />
	    <hr />
	    <?=_NOME;?> <br />
	    <input name='nome' type="text" value="" /> <br />
	    <?=_EMAIL;?><br />
	    <input name='email' type="text" value="" /> <br />
	    <?=_SITO_WEB;?><br />
	    <input name='web' type="text" value="" /> <br />
	    <?=_PROFESSIONE;?><br />
	    <input name='professione' type="text" value="" /> <br />
	    <?=_PROVENIENZA;?><br />
	    <input name='provenienza' type="text" value="" /> <br />
	    <?=_AVATAR;?><br />
	    <?php
    if ($user_avatar=="")$user_avatar="avtr00.png";
		if (substr($user_avatar,0,5)=="http:"){ ?>
		    <img src="<?=$user_avatar?>" border='1' name='pre_avatar' />
		<?php } else { ?>
		    <img src="libs/avatars/<?=$user_avatar?>" border='1' name='pre_avatar' />
		<?php } ?>
	    <br />
	    <select name='avatar' onchange="document.reguser.pre_avatar.src='libs/avatars/'+reguser.avatar.options[reguser.avatar.selectedIndex].text" >
		<?php
		    $hdir=opendir("extras/avatars");
		    $i=0;
		    while (false !== ($f= readdir($hdir))){
			if ($f[0]!="."){
			    $listfiles[$i]=$f;
			    $i++;
			}
		    }
		    echo("<option>$user_avatar</option>\n");
		    foreach( $listfiles as $filesel){
			    echo("<option>$filesel</option>\n");
		    }
		?>
	    </select>
	   <?=_IMMAGINE_URL;?><input name='ext_avatar' type="text" value="" onkeyup="document.reguser.pre_avatar.src=''+document.reguser.ext_avatar.value" /> <br />
	    <br />
	    <?=_FIRMA;?><br />
	    <input name='firma' type="text" value="" /> <br />
	    <?=_THEME;?><br />
	    <select name='theme' >
		<?php
		    $hdir=opendir("themes/");
		    $i=0;
		    while (false !== ($f= readdir($hdir))){
			if ($f[0]!="."){
			    $listthemes[$i]=$f;
			    $i++;
			}
		    }
		    echo("<option>$user_theme</option>\n");
		    foreach( $listthemes as $themesel){
			    echo("<option>$themesel</option>\n");
		    }
		?>
      </select>

	    <hr />
	    <input type="submit" value="<?=_REGISTER_USER;?>"><br />
	  </form>
        <?php }else{ //se ti sei appena registrato ?>
          <b> <?=_GRAZIE;?> <?=$_POST['user'] ?> <?=_PER_ESSERTI_REGISTRATO;?> <b><br/>
          <b><?=_ORA_PUOI;?> <i><?=_ENTRARE;?></i></b>
        <?php } ?>
      <?php }else{ // se sei gia autenticato ?>
	<? include "datas/sb/".sb_get()."/users/$user";
	$avatar=$_GET['avatar'];
	if ($avatar!="")$user_avatar=$avatar;//autoreload dell'avatar
	?>
        <form name="reguser" action="reguser.php?user_op=moduser" method="post" enctype="multipart/form-data" onsubmit="if( document.reguser.password.value != document.reguser.password2.value ){alert('<?=_PASSWORD_NON_CORRETTA_REINSERIRE;?>');return false;} ">
        <b><?=_USER;?></b> <?=$user;?><br />
        <b><?=_PASSWORD;?></b><input name='password' type="password" value=""/>
	<b><?=_RETYPE_PASSWORD;?></b><input name='password2' type="password" value="" /><br />
        <hr />
	<?=_NOME;?> <br />
	<input name='nome' type="text" value="<?=$user_nome?>" /> <br />
	<?=_EMAIL;?><br />
	<input name='email' type="text" value="<?=$user_email?>" /> <br />
	<?=_SITO_WEB;?><br />
	<input name='web' type="text" value="<?=$user_web?>" /> <br />
	<?=_PROFESSIONE;?><br />
	<input name='professione' type="text" value="<?=$user_professione?>" /> <br />
	<?=_PROVENIENZA;?><br />
	<input name='provenienza' type="text" value="<?=$user_provenienza?>" /> <br />
	<?=_AVATAR;?><br />
	    <?php if ($user_avatar!="") {
		if (substr($user_avatar,0,5)=="http:"){?>
		    <img src="<?=$user_avatar?>" border='1' name='pre_avatar' />
		<?php } else { ?>
		    <img src="libs/avatars/<?=$user_avatar?>" border='1' name='pre_avatar' />
		<?php } ?>
	    <?php } ?>
	    <br />
	    <select name='avatar' onchange="document.reguser.pre_avatar.src='extras/avatars/'+reguser.avatar.options[reguser.avatar.selectedIndex].text" />
		<?php
		    $hdir=opendir("libs/avatars");
		    $i=0;
		    while (false !== ($f= readdir($hdir))){
			if ($f[0]!="."){
			    $listfiles[$i]=$f;
			    $i++;
			}
		    }
		    $i=0;
		    echo("<option>$user_avatar</option>\n");
		    foreach( $listfiles as $filesel){
          echo("<option>$filesel</option>\n");
          if ($filesel==$user_avatar)$def=$i+1;
          $i++;
		    }
        echo "<script>document.reguser.avatar.selectedIndex='$def';</script>";

		?>
	    </select>
	    <?=_IMMAGINE_URL;?><input name='ext_avatar' type="text" value="" onkeyup="document.reguser.pre_avatar.src=''+document.reguser.ext_avatar.value" /> <br />
	    <br />

	<?=_FIRMA;?><br />
	<input name='firma' type="text" value="<?=$user_firma?>" /> <br />

	<?=_THEME;?><br />
	    <select name='theme' >
		<?php
		    $hdir=opendir("themes/");
		    $i=0;
		    while (false !== ($f= readdir($hdir))){
			if ($f[0]!="."){
			    $listthemes[$i]=$f;
			    $i++;
			}
		    }
		    echo("<option>$user_theme</option>\n");
		    foreach( $listthemes as $themesel){
			    echo("<option>$themesel</option>\n");
		    }
		?>
      </select>
        <hr />
        <input type="submit" value="<?=_UPDATE_USER;?>"><br />
 	<br />
	<hr />
        <input type='button' value='<?=_REMOVE;?> <?=$user?>' onclick="javascript:location='reguser.php?user_op=deluser';" />
        </form>
      <?php  } ?>
